package Exception;

import java.util.Scanner;

public class test1 {
    public static void main(String[] args) {
        try {
            Scanner scan = new Scanner(System.in);
            System.out.println("请输入被除数：");
            int num1 = scan.nextInt();
            System.out.println("请输入除数：");
            int num2 = scan.nextInt();
            System.out.println(num1/num2);

        }catch (Exception ex){//catch(InputMismatchException ex){}//对对应类型异常捕获//可以多个catch抓对应异常；但父类要写在下面
//            System.out.println("程序出错");
            System.out.println(ex.getMessage());
            ex.printStackTrace();
//            throw ex;直接抛异常，后面代码不执行！！

        }finally {//不会放入大量代码，一种情况finally不会执行：System.exit(0);若try中存在return，则先执行finally；
            System.out.println("运行结束！！");
        }
        System.out.println("运行结束！！！");
    }
}
class myexception extends Exception{
    public void prints(){
        System.out.println("有错");
    }

    public myexception(String message) {
        super(message);
    }
}

